package core.proto.vis.action;

import java.util.Iterator;

import prefuse.Visualization;
import prefuse.action.GroupAction;
import prefuse.data.tuple.TupleSet;
import prefuse.visual.EdgeItem;
import prefuse.visual.NodeItem;

/**
 * Switch the root of the tree by requesting a new spanning tree at the desired
 * root
 * 
 * @author Bill
 */
public class ShowSearchResultEdgeAction extends GroupAction
{
    // private static final SimpleLogger LOGGER = SimpleLogger.getLogger();

    public ShowSearchResultEdgeAction() {
    }

    public void run( double frac ) {
        TupleSet edges = m_vis.getGroup( Visualization.SEARCH_ITEMS );
        if( edges == null || edges.getTupleCount() == 0 )
            return;

        Object o = null;
        @SuppressWarnings("rawtypes")
        Iterator tuples = edges.tuples();
        while( tuples.hasNext() ) {
            o = tuples.next();
            if( !(o instanceof EdgeItem) ) {
                continue;
            }
            EdgeItem edge = (EdgeItem) o;
            edge.setVisible( true );

            ((NodeItem) edge.getSourceNode()).setVisible( true );
            ((NodeItem) edge.getTargetNode()).setVisible( true );
        }
    }
}
